package actions;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DBModel;

@WebServlet
public class InsertVenueAction extends Action{

	public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request,HttpServletResponse response){
		try {
			int venueId=-1;
			String venueName=request.getParameter("venueName");
			String venueAddress=request.getParameter("venueAddress");
			String venueDescription=request.getParameter("venueDescription");
			int venueCapacity=Integer.parseInt(request.getParameter("venueCapacity"));
			
			DBModel db = new DBModel();
			
			venueId = db.insertVenue(venueName,venueAddress,venueDescription,venueCapacity);
			request.setAttribute("venueId", venueId);
			db.commit();
			db.close();
			return new ActionForward(mapping.findForward("success").getPath()+"?id="+venueId);
		} catch (Exception e){
			e.printStackTrace();
			request.setAttribute("error", e.toString());
			return null;
		}	
	}
}
